<?php
require_once "./db_config.php";
$arr=[];
if(isset($_POST['id'])){
    $id=$_POST['id'];
//    $time=$_POST['time'];
//    if($time==''){
//        $timeInfo="";
//    }else{
//    }
    $sql="SELECT * FROM turnlist WHERE id='$id'";
    $result=mysqli_query($conn,$sql);
    if (mysqli_num_rows($result) > 0) {
        while($row = mysqli_fetch_array($result)) {
            $arr[]=$row;
        }
        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
        mysqli_close($conn);
    } else {
        echo "0 结果";
    }
}else{
    if(isset($_POST['name'])){
        $name=$_POST['name'];
        $sql="SELECT dept,start_date FROM turnlist WHERE name='$name'";
        $result=mysqli_query($conn,$sql);
        if (mysqli_num_rows($result) > 0) {
            while($row = mysqli_fetch_array($result)) {
                $arr[]=$row;
            }
            echo json_encode($arr,JSON_UNESCAPED_UNICODE);
            mysqli_close($conn);
        } else {
            echo "0 结果";
        }
    }else{
        $sql="SELECT distinct name,id,`from` FROM turnlist";
        $result=mysqli_query($conn,$sql);
        if (mysqli_num_rows($result) > 0) {
            while($row = mysqli_fetch_array($result)) {
                $arr[]=$row;
            }
            echo json_encode($arr,JSON_UNESCAPED_UNICODE);
            mysqli_close($conn);
        } else {
            echo "0 结果";
        }
    }

//    $sql="SELECT dept,start_date,name FROM turnlist";
//    $result=mysqli_query($conn,$sql);
//    if (mysqli_num_rows($result) > 0) {
//        while($row = mysqli_fetch_array($result)) {
//            $arr[]=$row;
//        }
//        echo json_encode($arr,JSON_UNESCAPED_UNICODE);
//        mysqli_close($conn);
//    } else {
//        echo "0 结果";
//    }
}
mysqli_close($conn);
?>
